// pages/staff/ticketdetail.js
var app = getApp()
Page({
    data: {
        user:[],
        id:'',
        detail:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const user = wx.getStorageSync('user');
        this.setData({
            user: user,
            id: options.id
            // id: 1133
        })
        this.getTicketDetail();
    },
    getTicketDetail(){
        var that = this;
          app.util.request({
            url: 'entry/wxapp/ticketdetail',
            data:{
                op: 'detail',
                id: that.data.id
            },
            cachetime:0,
            success: function(res){
                if(res.data.errno == 0){
                    that.setData({
                        detail: res.data.data
                    })
                }
            },
            fail: function (res) {
                wx.showToast({
                    title: res.data.message,
                    icon: 'none',
                    duration: 2000,
                    success: function () {          
                      setTimeout(function () {
                        wx.redirectTo({
                          url: '/pages/staff/inputdetail'
                        })
                      }, 2000) //延迟时间
                    }
                  });
                return false;
              }
          })
    },
    // 删除
    delete(){
        var that = this;
          app.util.request({
            url: 'entry/wxapp/ticketdetail',
            data:{
                op: 'delete',
                uid: that.data.user.id,
                name: that.data.user.name,
                id: that.data.id
            },
            cachetime:0,
            success: function(res){
                if(res.data.errno == 0){
                    wx.showToast({
                        title: res.data.message,
                        icon: 'none',
                        duration: 2000,
                        success: function () {          
                          setTimeout(function () {
                            wx.redirectTo({
                              url: '/pages/staff/inputdetail'
                            })
                          }, 2000) //延迟时间
                        }
                      });
                }
            }
          })
    },
    // 发券
    give:function(e){
        var id = this.data.id;
        wx.navigateTo({
            url: '/pages/staff/giveout?tid='+id,
          })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})